﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JeanFish.WeChat
{
    public class AccessHelper
    {
        public static bool CheckSignature(string signature,string token,string timestamp,string nonce)
        {
            string[] parameters =  { token, timestamp, nonce };
            Array.Sort(parameters);
            var sha1 = System.Security.Cryptography.SHA1.Create();
            var input=System.Text.Encoding.UTF8.GetBytes(string.Join("",parameters));
            var output=System.Text.Encoding.UTF8.GetString(sha1.ComputeHash(input));
            return string.Equals(signature, output);
        }
    }
}
